/**
 * @author zqd	差旅小组
 *
 * 上午10:10:38
 */
package com.cbts.service.info.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.transaction.annotation.Transactional;

import com.cbts.dao.HotelDao;
import com.cbts.dao.TrafficDao;
import com.cbts.dao.TravelStandardDao;
import com.cbts.entity.Hotel;
import com.cbts.entity.Traffic;
import com.cbts.entity.TravelStandard;
import com.cbts.service.info.TravelInfoService;
import com.cbts.util.Constant;
import com.cbts.util.Page;

public class TravelInfoServiceImpl implements TravelInfoService {
	protected TrafficDao trafficDao;
	protected HotelDao hotelDao;
	protected TravelStandardDao travelStandardDao;
	
	public void setTrafficDao(TrafficDao trafficDao) {
		this.trafficDao = trafficDao;
	}
	public void setHotelDao(HotelDao hotelDao) {
		this.hotelDao = hotelDao;
	}
	public void setTravelStandardDao(TravelStandardDao travelStandardDao) {
		this.travelStandardDao = travelStandardDao;
	}
	/* 
	 * @see com.cbts.service.info.TravelInfoService#getInfo(int)
	 */
	@SuppressWarnings("unchecked")
	public Page getInfo(int type,int pageNum) {
		// zqd 下午02:32:46
		/*if(type==0){	//hotel	
			System.out.println(hotelDao.findAll().size());
			return hotelDao.findAll();
		}
		else return null;*/
		switch(type){
		case 0:
			return hotelDao.findAllByPage(pageNum, Constant.PAGE);
		case 1:
			return trafficDao.findAllByPage(pageNum, Constant.PAGE);
		case 2:
			return travelStandardDao.findAllByPage(pageNum, Constant.PAGE);
		default:
			return null;
		}
	}
	/* 
	 * @see com.cbts.service.info.TravelInfoService#saveInfo(java.io.Serializable, int)
	 */
	public boolean saveInfo(Serializable t, int type) {
		// zqd 下午02:32:46
/*		if(type==0){
			hotelDao.save(t);
			return true;
		}
		return false;*/
		switch(type){
		case 0:
			return hotelDao.save((Hotel) t);
		case 1:
			return trafficDao.save((Traffic) t);
		case 2:
			return travelStandardDao.save((TravelStandard) t);
		default:
			return false;
		}
	}
	/* 
	 * @see com.cbts.service.info.TravelInfoService#delete(java.io.Serializable, int)
	 */
	public boolean deleteInfo(Serializable t, int type) {
		// zqd 下午04:30:27
		switch(type){
		case 0:
			return hotelDao.delete((Hotel) t);
		case 1:
			return trafficDao.delete((Traffic) t);
		case 2:
			return travelStandardDao.delete((TravelStandard) t);
		default:
			return false;
		}
	}
	/* 
	 * @see com.cbts.service.info.TravelInfoService#getHotelInfoById(java.io.Serializable)
	 */
	public Hotel getHotelInfoById(Serializable id) {
		// zqd 下午04:30:27
		return (Hotel) hotelDao.get(id);
	}
	/* 
	 * @see com.cbts.service.info.TravelInfoService#getTrafficInfoById(java.io.Serializable)
	 */
	public Traffic getTrafficInfoById(Serializable id) {
		// zqd 下午04:30:27
		return (Traffic) trafficDao.get(id);
	}
	/* 
	 * @see com.cbts.service.info.TravelInfoService#getTravelStandardInfoById(java.io.Serializable)
	 */
	public TravelStandard getTravelStandardInfoById(Serializable id) {
		// zqd 下午04:30:27
		return (TravelStandard) travelStandardDao.get(id);
	}
	/* 
	 * @see com.cbts.service.info.TravelInfoService#update(java.io.Serializable, int)
	 */
	public boolean updateInfo(Serializable t, int type) {
		// zqd 下午04:30:27
		switch(type){
		case 0:
			return hotelDao.update((Hotel) t);
		case 1:
			return trafficDao.update((Traffic) t);
		case 2:
			return travelStandardDao.update((TravelStandard) t);
		default:
			return false;
		}
	}
	
	/* 
	 * @see com.cbts.service.info.TravelInfoService#existsCheck(java.lang.Object, int)
	 */
	public boolean existsCheck(Object[] o, int type, int oper) {
		// zqd 下午04:54:30
		if(oper==0){
			switch(type){
			case 0:
				return hotelDao.queryUnique("and o.hotel = ?", o)!=null;
			case 1:
				return trafficDao.queryUnique("and o.traffic = ? and o.standard = ?", o)!=null;
			case 2:
				return travelStandardDao.queryUnique("and o.grade = ?", o)!=null;
			}
		}else if(oper==1){
			switch(type){
			case 0:
				return hotelDao.queryUnique("and o.hotel = ? and o.hotelId <> ?", o)!=null;
			case 1:
				return trafficDao.queryUnique("and o.traffic = ? and o.standard = ? and o.trafficId <> ?", o)!=null;
			case 2:
				return travelStandardDao.queryUnique("and o.grade = ? and o.standardId <> ?", o)!=null;
			}
		}
		return false;
	}
	/* 
	 * @see com.cbts.service.info.TravelInfoService#getInfo(int)
	 */
	public Page getInfo(int type) {
		// zqd 下午05:45:00
		switch(type){
		case 0:
			return hotelDao.findAll();
		case 1:
			return trafficDao.findAll();
		case 2:
			return travelStandardDao.findAll();
		default:
			return null;
		}
	}
	
	
	
}
